package com.tz.online.order.service.impl;

import java.util.List;

import com.tz.online.common.PageBean;
import com.tz.online.entity.Order;
import com.tz.online.entity.User;
import com.tz.online.order.dao.IOrderDao;
import com.tz.online.order.service.IOrderService;
import com.tz.online.util.BeanFactory;

public class OrderServiceImpl implements IOrderService {
	
	private IOrderDao ordDao = (IOrderDao) BeanFactory.getBean("orderDao");

	@Override
	public void save(Order o) {
		//
		if(o != null) {
			ordDao.save(o);
		}
	}

	@Override
	public void delete(Order o) {
		//
		if(o != null) {
			ordDao.delete(o);
		}
	}

	@Override
	public Order findById(Long id) {
		//
		if(id != null) {
			return ordDao.findById(id);
		}
		return null;
	}

	@Override
	public PageBean<Order> queryByPage(User user, int now, int size) {
		//调用Dao来获取数据
		List<Order> orders = ordDao.selectByPage(user, now, size);
		//获取总记录数据
		int count = ordDao.rowCount(user);
		//创建 PageBean 对象
		PageBean<Order> pb = new PageBean<>(count, size);
		//设置数据
		pb.setDatas(orders);
		pb.setCurrent(now);
		//返回
		return pb;
	}
	

}
